import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: 'External Link', icon: 'link' }
      }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

//异步挂载的路由
//动态需要根据权限加载的路由表 
// export const asyncRouterMap = [
//   {
//     path: '/permission',
//     component: Layout, 
//     redirect: '/permission/permission1',
//     name: 'permission',
//     meta: { title: 'permission', icon: 'link', role: ['admin']},
//     children: [
//       {
//         path: 'permission1',
//         name: 'permission1',
//         component: () => import('@/views/permission/permission1/index'),
//         meta: { title: 'permission1', role: ['admin']}
//       },
//       {
//         path: 'permission2',
//         name: 'permission2',
//         component: () => import('@/views/permission/permission2/index'),
//         meta: { title: 'permission2', role: ['admin']}
//       }
//     ]
//     }, {
//     path: '/commonUser',
//     component: () => import('@/views/commonUser/index.vue'),
//     name: '权限测试c',
//     meta: { role: ['commonUser'] } 
//   },{
//      path: '*', redirect: '/404', hidden: true 
//     }
//   ]

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}



export default router
